/*
 * @author wilbur.ma@qq.com
 * @date 2011.06.01
 * Requrie jquery
 */

function fold_all(all_div) {
	all_div.each(function() {fold_div($(this))});
}

function show_all(all_div) {
	all_div.each(function() {show_div($(this))});
}

function fold_all_except(all_div, div) {
	all_div.each(function() {
			if (this.id != div.attr("id"))
				fold_div($(this));
			else
				toggle_div($(this));
		}
	);
 }
 
 function set_div_img_open(div) {
	set_div_img(div, true);
 }
 
 function set_div_img_closed(div) {
	set_div_img(div, false);
 }
 
 function set_div_img(div, state_p) {
	var img = div.find("img")[0];
	if (state_p == true) {
		$(img).attr("src", "../img/open.png");
		$(img).attr("alt", "open");
	} else {
		$(img).attr("src", "../img/closed.png");
		$(img).attr("alt", "close");
	}
 }
 
 function fold_div(div) {
	div.children("div:nth-child(2)").hide("fast");
	set_div_img_closed(div);
 }
 
 function show_div(div) {
	div.children("div:nth-child(2)").show("fast");
	set_div_img_open(div);
 }
 
 function is_div_folded(div) {
	return div.children("div:nth-child(2)").is(":hidden");
 }
 
 function toggle_div(div) {
	if (is_div_folded(div))
		show_div(div);
	else
		fold_div(div);
 }